<script type="text/javascript">
    /**
     * 普通上传图片
     */
    layui.use(['form', 'jquery','laydate'], function () {
        $ = layui.jquery;
        var form = layui.form,
            laydate = layui.laydate;
            laydate.render({
			    elem: '#test16'
			    ,type: 'date'
			    ,range: true
			});
	        var type = 1;
	        //活动类型选择
	        form.on('select(activity_type)',function(data){
	        	type = data.value; 
	        	if( type == 1 ){   //满减
	        		$("#decrease").show();
                    $("#discount").hide();
                }else if( type == 2 ){
                    $("#decrease").hide();
                    $("#discount").show();
	        	}else{
                    $("#decrease").hide();
                    $("#discount").hide();
                }
	        })

	    	
	    	var ind = 1;
            //添加活动类型框
            $("body").on('click','#add_decrease',function(){
            	ind++;
                var str_decrease = '<div>'+
                            '<div class="layui-inline">'+
                                '<label class="layui-form-label">满</label>'+
                                '<div class="layui-input-block">'+
                                    '<input type="tel" name="price_all['+ind+']" autocomplete="off" class="layui-input">'+
                                '</div>'+
                            '</div>'+
                            '<div class="layui-inline" style="margin-left: -87px;">'+
                                '<label class="layui-form-label">减</label>'+
                                '<div class="layui-input-block">'+
                                    '<input type="text" name="price['+ind+']" autocomplete="off" class="layui-input">'+
                                '</div>'+
                            '</div>'+
                            '<button class="layui-btn" style="margin-top: -15px;margin-left: 4px;" id="del_decrease">删除</button>'+
                        '</div>';
                 if( type  == 1 ){
                 	$("#decrease").append(str_decrease);
                 }
                return false;
            })


            //添加活动类型框
            $("body").on('click','#add_discount',function(){
                ind++;
                var str_discount = '<div>'+
                    '<div class="layui-inline">'+
                    '<label class="layui-form-label">满</label>'+
                    '<div class="layui-input-block">'+
                    '<input type="tel" name="price_all['+ind+']" autocomplete="off" class="layui-input">'+
                    '</div>'+
                    '</div>'+
                    '<div class="layui-inline" style="margin-left: -80px;">'+
                    '<label class="layui-form-label">打折</label>'+
                    '<div class="layui-input-block">'+
                    '<input type="text" name="price['+ind+']" autocomplete="off" class="layui-input">'+
                    '</div>'+
                    '</div>'+
                    '<button class="layui-btn" style="margin-top: -15px;margin-left: 4px;" id="del_decrease">删除</button>'+
                    '</div>';
                if( type  == 2 ){
                    $("#discount").append(str_discount);
                }
                return false;
            })


            //删除活动类型框
            $("body").on('click','#del_decrease',function(){
            	$(this).parent().remove();
            })

            var is_submit = false;
            //监听提交
            form.on('submit(btn_edit)', function (data) {
                if( is_submit ){
                    return false;
                }
                // is_submit = true;
                $.ajax({
                    url: js_url('shop-activity-store'),
                    type: 'post',
                    data: data.field,
                    dataType: "json",
                    success: function (result) {
                        if (result.state === 0) {
                            layer.msg(result.msg, {time: 1000, icon: 6}, function () {
                                //关闭当前frame
                                xadmin.close();
                                // 可以对父窗口进行刷新
                                xadmin.father_reload();
                            });
                        } else {
                            is_submit = false;
                            layer.msg(result.msg, {time: 2000, icon: 5});
                        }
                    }
                });
                return false;
            });

	})
</script>